import { Component } from '@angular/core';
import {DomSanitizer} from "@angular/platform-browser";
import {ActivatedRoute, Router} from "@angular/router";
import {api} from "@core/service/config/api";
import {DiskService} from "@core/service/DiskService";
import {BBYUtils} from "@shared/utils/BBYUtils";
import {NzMessageService} from "ng-zorro-antd/message";
import {FileInfo} from "@shared/models/FileInfo";
import {EditPermissionDialogContent} from "@/app/pages/disk/file-list/file-options/edit-permission-dialog-content";
import {NzModalService} from "ng-zorro-antd/modal";
import {InputDialogContent} from "@/app/pages/common/input-dialog-content";

export interface IMedia {
  title: string;
  src: string;
  type: string;
}
@Component({
  selector: 'app-video-page',
  templateUrl: './video-page.component.html',
  styleUrls: ['./video-page.component.scss']
})
export class VideoPageComponent {

  // url = 'http://vjs.zencdn.net/v/oceans1.mp4';
  safeUrl: any;
  fileId=''
  directId=''
  file:FileInfo|undefined
  constructor(
    private router: ActivatedRoute,
    private sanitizer: DomSanitizer,
    private diskService:DiskService,
    private message: NzMessageService,
    protected dialogService: NzModalService,
  ) {
    // this.params=router.getCurrentNavigation()?.extras.queryParams;
    router.queryParams.subscribe(
      (queryParams: any) => {
        this.fileId=queryParams.fileId||''
        this.directId=queryParams.directId||''
      }
    )
    this.loadFileInfo()
    this.safeUrl = this.sanitizer.bypassSecurityTrustUrl(`${api.video}/${this.fileId}?directId=${this.directId}`);  // 获取安全链接
  }

  loadFileInfo(){
    BBYUtils.handelResult(
      this.diskService.fileInfo(this.fileId),
      res => {
        this.file=res.data
      },
      res => {
        this.message.error(res.msg)
      }
    )

  }
  getUrl(url: string) {

  }

  reportClick() {
    if (!this.file) return;
    this.dialogService.create({
      nzTitle: '举报-' + this.file.name,
      nzContent: InputDialogContent,
      nzComponentParams: {
        placeholder:'请输入举报理由'
      },
      nzOnOk: (page) => new Promise(
        resolve => {

          // this.diskService.reportFile(this.fileId,page.value)
        })
    })
  }

  ediePermissionClick(){
    if (!this.file) return;
    this.dialogService.create({
      nzTitle: '修改权限-' + this.file.name,
      nzContent: EditPermissionDialogContent,
      nzComponentParams: {
        file:this.file,
        names:[this.file.name]
      },
      nzOnOk: (page) => new Promise(
        resolve => {
          let data = {
            ids: [page.file.id],
            permission: page.file.permission
          }
          BBYUtils.handelResult(
            this.diskService.editPermission(data),
            res => {
              console.log(res)
              resolve()
              this.message.success("权限修改完成!");
            },
            res => {
              resolve()
              this.message.error(res.msg)
            }
          )
        })
    })
  }

  downloadClick() {
    this.diskService.download(this.fileId,this.directId)
  }
}
